package com.hrt.datasender.web.operInfo;

import com.btcode.web.core.annotation.RequestMapping;
import com.btcode.web.core.controller.Controller;
import com.hrt.common.web.DSRequestUnit;
import com.hrt.datasender.mq.model.OperInfoModel;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author wencheng
 *
 */
@RequestMapping(path = "OperInfo")
public class OperInfoController extends Controller {

    @RequestMapping(path = "getOperInfo")
    public void getOperInfo(ServletRequest arg0, ServletResponse arg1) throws IOException {
        String server = DSRequestUnit.getString("server");
        OperInfoModel model = OperInfoService.getInstance().getOperInfo(server);
        if(model==null){
            model = new OperInfoModel(null);
        }
        model.setOperInfoSize(OperInfoService.getInstance().getOperInfoSize());
        model.setOperErrorInfoSzie(OperInfoService.getInstance().getOperErrorSize());
        success(model);
    }

    @RequestMapping(path = "getOperErrorInfo")
    public void getOperErrorInfo(ServletRequest arg0, ServletResponse arg1) throws IOException {
        ArrayList<OperInfoModel> operErrorList = OperInfoService.getInstance().getOperErrorList();
        success(operErrorList);
    }

    @RequestMapping(path = "clearOperInfo")
    public void clearOperInfo(ServletRequest arg0, ServletResponse arg1) throws IOException {
        OperInfoService.getInstance().clearOperInfo();
        success(null);
    }

    /**
     * 获取数据存储信息
     * @param arg0
     * @param arg1
     * @throws IOException
     */
    @RequestMapping(path = "getDataStoragerInfo")
    public void getDataStoragerInfo(ServletRequest arg0, ServletResponse arg1)
            throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException{
        String platformId = DSRequestUnit.getString("platformId");
        HashMap<String,String> result = OperInfoService.getInstance().getDataStorageInfo(platformId);
        success(result);
    }


}
